package com.he.security.rsocket.authentication;

import com.he.security.core.GrantedAuthority;
import com.he.security.core.authority.AuthorityUtils;
import com.he.security.rsocket.api.PayloadExchange;
import com.he.security.rsocket.api.PayloadInterceptor;
import com.he.security.rsocket.api.PayloadInterceptorChain;
import org.springframework.core.Ordered;
import org.springframework.util.Assert;
import reactor.core.publisher.Mono;

import java.util.List;

public class AnonymousPayloadInterceptor implements PayloadInterceptor, Ordered {

    private String key;
    private Object principal;
    private List<GrantedAuthority> authorities;

    private int order;


    public AnonymousPayloadInterceptor(String key) {
        this(key, "anonymousUser", AuthorityUtils.createAuthorityList("ROLE_ANONYMOUS"));
    }


    public AnonymousPayloadInterceptor(String key, Object principal, List<GrantedAuthority> authorities) {
        Assert.hasLength(key, "key cannot be null or empty");
        Assert.notNull(principal, "Anonymous authentication principal must be set");
        Assert.notNull(authorities, "Anonymous authorities must be set");
        this.key = key;
        this.principal = principal;
        this.authorities = authorities;
    }

    public void setOrder(int order) {
        this.order = order;
    }

    @Override
    public int getOrder() {
        return this.order;
    }

    @Override
    public Mono<Void> intercept(PayloadExchange exchange, PayloadInterceptorChain chain) {
        return null;
    }


}
